<template>
  <a-card :bordered="false">
    <div>
      <a-tabs v-model="activeKey" @change="handleChangeTab">
        <a-tab-pane key="notGenerated" tab="暂存中">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="2">
              <a-col :xl="8" :lg="11" :md="12" :sm="24">
                <a-form-item label="开始日期">
                  <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="startTime_begin"></j-date>
                  <span class="query-group-split-cust"></span>
                  <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="startTime_end"></j-date>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                  <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                  <a-button type="primary" @click="searchResetUnCreated" icon="reload" style="margin-left: 8px">重置</a-button>
                </span>
              </a-col>
            </a-row>
          </a-form>
          <a-button @click="handleAdd" type="primary" icon="plus" style="margin-bottom: 5px; margin-right: 5px">新增
          </a-button>
          <a-button type="primary" icon="download" @click="handleExportXls('资金申请-暂存中')">导出</a-button>
          <a-table
            ref="table"
            size="middle"
            bordered
            :rowKey="
              (record, index) => {
                return record.detailId
              }
            "
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="needEditColumns"
            :dataSource="notGeneratedTable.dataSource"
            :pagination="notGeneratedTable.ipagination"
            :loading="notGeneratedTable.loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            @change="handleTableChange"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt=""
                style="max-width: 80px; font-size: 12px; font-style: italic"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
              <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
                下载
              </a-button>
            </template>

            <span slot="action" slot-scope="text, record">
              <a v-if="record.status < 0" @click="handleEdit(record)">编辑</a>
              <a-divider type="vertical"></a-divider>
              <act-apply-btn
                v-show="record.status < 0"
                @success="loadData"
                :data-id="record.id"
                :serviceName="serviceName"
                :variables="record"
              ></act-apply-btn>
              <!--              <act-historic-detail-btn :data-id="record.id"></act-historic-detail-btn>-->
              <a-divider type="vertical" />
              <a-dropdown>
                <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                <a-menu slot="overlay">
                  <a-menu-item>
                    <a @click="handleDetail(record)">详情</a>
                  </a-menu-item>
                  <a-menu-item>
                    <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                      <a>删除</a>
                    </a-popconfirm>
                  </a-menu-item>
                </a-menu>
              </a-dropdown>
            </span>
          </a-table>
        </a-tab-pane>
        <a-tab-pane key="needEdit" tab="需修改">
          <a-button type="primary" icon="download" style="margin-bottom: 5px"
                    @click="handleExportXls('资金申请-需修改')">导出
          </a-button>
          <a-table
            ref="needEditTable"
            size="middle"
            bordered
            :rowKey="
              (record, index) => {
                return record.detailId
              }
            "
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="columns"
            :dataSource="needEditTable.dataSource"
            :pagination="needEditTable.ipagination"
            :loading="needEditTable.loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            @change="handleTableChange"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt=""
                style="max-width: 80px; font-size: 12px; font-style: italic"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
              <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
                下载
              </a-button>
            </template>

            <span slot="action" slot-scope="text, record">
              <a v-if="record.status < 0" @click="handleEdit(record)">编辑</a>
              <a-divider type="vertical"></a-divider>
              <act-apply-btn
                v-show="record.status < 0"
                @success="loadData"
                :data-id="record.id"
                :serviceName="serviceName"
                :variables="record"
              ></act-apply-btn>
              <act-historic-detail-btn :data-id="record.id"></act-historic-detail-btn>
              <a-divider type="vertical" />
              <a-dropdown>
                <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                <a-menu slot="overlay">
                  <a-menu-item>
                    <a @click="handleDetail(record)">详情</a>
                  </a-menu-item>
                  <a-menu-item>
                    <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                      <a>删除</a>
                    </a-popconfirm>
                  </a-menu-item>
                </a-menu>
              </a-dropdown>
            </span>
          </a-table>
        </a-tab-pane>
        <a-tab-pane key="approving" tab="审批中">
          <a-button type="primary" icon="download" @click="handleExportXls('资金申请-审批中')">导出</a-button>
          <a-table
            ref="approvingTable"
            size="middle"
            bordered
            :rowKey="
              (record, index) => {
                return record.detailId
              }
            "
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="columns"
            :dataSource="approvingTable.dataSource"
            :pagination="approvingTable.ipagination"
            :loading="approvingTable.loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            @change="handleTableChange"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt=""
                style="max-width: 80px; font-size: 12px; font-style: italic"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
              <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
                下载
              </a-button>
            </template>

            <span slot="action" slot-scope="text, record">
              <act-historic-detail-btn :data-id="record.id"></act-historic-detail-btn>
              <a-divider type="vertical" />
              <a-popconfirm  v-if="record.actStatus != '撤回'" title="确定取消申请吗?" @confirm="() => handelSubmitCancel(record)">
                <a href="javascript:;">取消申请</a>
              </a-popconfirm>
              <a-divider type="vertical" />
              <a @click="handleUpdate(record)">变更</a>
              <a-divider type="vertical" />
              <a-dropdown>
                <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                <a-menu slot="overlay">
                  <a-menu-item>
                    <a @click="handleDetail(record)">详情</a>
                  </a-menu-item>
                </a-menu>
              </a-dropdown>
            </span>
          </a-table>
        </a-tab-pane>
        <a-tab-pane key="approved" tab="已审批">
          <a-button type="primary" icon="download" style="margin-bottom: 5px"
                    @click="handleExportXls('资金申请-已审批')">导出
          </a-button>
          <a-table
            ref="approvedTable"
            size="middle"
            bordered
            :rowKey="
              (record, index) => {
                return record.detailId
              }
            "
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="columns"
            :dataSource="approvedTable.dataSource"
            :pagination="approvedTable.ipagination"
            :loading="approvedTable.loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            @change="handleTableChange"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt=""
                style="max-width: 80px; font-size: 12px; font-style: italic"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
              <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
                下载
              </a-button>
            </template>

            <span slot="action" slot-scope="text, record">
              <act-historic-detail-btn :data-id="record.id"></act-historic-detail-btn>
              <a-divider type="vertical" />
              <a-dropdown>
                <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                <a-menu slot="overlay">
                  <a-menu-item>
                    <a @click="handleUpdate(record)">变更</a>
                  </a-menu-item>
                  <a-menu-item v-if="record.isOpen === '0'">
                    <a @click="handelOpen(record)">开启 </a>
                  </a-menu-item>
                  <a-menu-item v-if="record.isOpen === '1'">
                    <a @click="handelClose(record)">关闭</a>
                  </a-menu-item>
                  <a-menu-item>
                    <a @click="handleDetail(record)">详情</a>
                  </a-menu-item>
                  <a-menu-item>
                    <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                      <a>删除</a>
                    </a-popconfirm>
                  </a-menu-item>
                </a-menu>
              </a-dropdown>
            </span>
          </a-table>
        </a-tab-pane>
        <a-tab-pane key="toBePaid" tab="待支付">
          <a-table
            ref="toBePaidTable"
            size="middle"
            bordered
            :rowKey="
              (record, index) => {
                return record.detailId
              }
            "
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="columns"
            :dataSource="toBePaidTableTable.dataSource"
            :pagination="toBePaidTableTable.ipagination"
            :loading="toBePaidTableTable.loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            @change="handleTableChange"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt=""
                style="max-width: 80px; font-size: 12px; font-style: italic"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
              <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
                下载
              </a-button>
            </template>

            <span slot="action" slot-scope="text, record">
              <a @click="handleUpdate(record)">变更</a>
              <a-divider type="vertical" />
              <a @click="handleDetail(record)">详情</a>
              <a-divider type="vertical" />
               <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                      <a>删除</a>
               </a-popconfirm>
            </span>
          </a-table>
        </a-tab-pane>
        <a-tab-pane key="paid" tab="已支付">
          <a-table
            ref="paidTable"
            size="middle"
            bordered
            :rowKey="
              (record, index) => {
                return record.detailId
              }
            "
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="paidColumns"
            :dataSource="paidTableTable.dataSource"
            :pagination="paidTableTable.ipagination"
            :loading="paidTableTable.loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            @change="handleTableChange"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt=""
                style="max-width: 80px; font-size: 12px; font-style: italic"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
              <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
                下载
              </a-button>
            </template>

            <span slot="action" slot-scope="text, record">
              <a @click="handleDetail(record)">详情</a>
            </span>
          </a-table>
        </a-tab-pane>
      </a-tabs>
    </div>

    <funding-application-modal ref="modalForm" @ok="modalFormOk"></funding-application-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import FundingApplicationModal from './modules/FundingApplicationModal'
import FeeApplicationModal from '@views/business/procurement/modules/FeeApplicationModal.vue'
import ActHistoricDetailBtn from '@views/flowable/components/ActHistoricDetailBtn.vue'
import ActApplyBtn from '@views/flowable/components/ActApplyBtn.vue'
import moment from 'dayjs'
import { deleteAction, getAction, httpAction } from '@api/manage'
import { stopProcess } from '@views/flowable/api/process'

export default {
  name: 'FundingApplicationList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    ActApplyBtn, ActHistoricDetailBtn,
    FundingApplicationModal
  },
  data() {
    return {
      description: '资金申请管理页面',
      serviceName: 'fundingApplicationService',
      activeKey: 'notGenerated',
      startTime_begin: this.startTime_begin ? `${this.startTime_begin}` : moment().subtract(7, 'days').format('YYYY-MM-DD'),
      startTime_end: this.startTime_end ? `${this.startTime_end}` : moment().format('YYYY-MM-DD'),
      dateFormat: 'YYYY-MM-DD',
      notGeneratedTable: {
        loading: false,
        dataSource: [],
        // 表头
        ipagination: {
          current: 1,
          pageSize: 30,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        }
      },
      needEditTable: {
        loading: false,
        dataSource: [],
        // 表头
        ipagination: {
          current: 1,
          pageSize: 30,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        }
      },
      approvingTable: {
        loading: false,
        dataSource: [],
        // 表头
        ipagination: {
          current: 1,
          pageSize: 30,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        }
      },
      approvedTable: {
        loading: false,
        dataSource: [],
        // 表头
        ipagination: {
          current: 1,
          pageSize: 30,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        }
      },
      toBePaidTableTable: {
        loading: false,
        dataSource: [],
        // 表头
        ipagination: {
          current: 1,
          pageSize: 30,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        }
      },
      paidTableTable: {
        loading: false,
        dataSource: [],
        // 表头
        ipagination: {
          current: 1,
          pageSize: 30,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        }
      },
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '资金申请单号',
          align: 'center',
          dataIndex: 'fundingApplicationNum'
        },
        {
          title: '供应商名称',
          align: 'center',
          dataIndex: 'vendorName'
        },
        {
          title: '单据类型',
          align: 'center',
          dataIndex: 'documentType_dictText'
        },
        {
          title: '所获物资',
          align: 'center',
          dataIndex: 'suppliesObtained'
        },
        {
          title: '申请金额',
          align: 'center',
          dataIndex: 'applicantAmount'
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'applyUserName'
        },
        {
          title: '申请日期',
          align: 'center',
          dataIndex: 'applicantDate',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '账面余额',
          align: 'center',
          dataIndex: 'bookBalance'
        },
        {
          title: '批准金额',
          align: 'center',
          dataIndex: 'approveAmount'
        },
        {
          title: '财务查询人',
          align: 'center',
          dataIndex: 'financeUserName'
        },
        {
          title: '查询日期',
          align: 'center',
          dataIndex: 'queryDate',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '制单人',
          align: 'center',
          dataIndex: 'createBy'
        },
        {
          title: '制单部门',
          align: 'center',
          dataIndex: 'sysOrgCode'
        },
        {
          title: '制单日期',
          align: 'center',
          dataIndex: 'createTime'
        },
        {
          title: '是否变更',
          align: 'center',
          dataIndex: 'isUpdate_dictText'
        },
        {
          title: '是否开启',
          align: 'center',
          dataIndex: 'isOpen_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      needEditColumns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '资金申请单号',
          align: 'center',
          dataIndex: 'fundingApplicationNum'
        },
        {
          title: '供应商名称',
          align: 'center',
          dataIndex: 'vendorName'
        },
        {
          title: '单据类型',
          align: 'center',
          dataIndex: 'documentType_dictText'
        },
        {
          title: '所获物资',
          align: 'center',
          dataIndex: 'suppliesObtained'
        },
        {
          title: '申请金额',
          align: 'center',
          dataIndex: 'applicantAmount'
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'applyUserName'
        },
        {
          title: '申请日期',
          align: 'center',
          dataIndex: 'applicantDate',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '账面余额',
          align: 'center',
          dataIndex: 'bookBalance'
        },
        {
          title: '财务查询人',
          align: 'center',
          dataIndex: 'financeUserName'
        },
        {
          title: '查询日期',
          align: 'center',
          dataIndex: 'queryDate',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '是否变更',
          align: 'center',
          dataIndex: 'isUpdate_dictText'
        },
        {
          title: '是否开启',
          align: 'center',
          dataIndex: 'isOpen_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      paidColumns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '资金申请单号',
          align: 'center',
          dataIndex: 'fundingApplicationNum'
        },
        {
          title: '供应商名称',
          align: 'center',
          dataIndex: 'vendorName'
        },
        {
          title: '单据类型',
          align: 'center',
          dataIndex: 'documentType_dictText'
        },
        {
          title: '所获物资',
          align: 'center',
          dataIndex: 'suppliesObtained'
        },
        {
          title: '申请金额',
          align: 'center',
          dataIndex: 'applicantAmount'
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'applyUserName'
        },
        {
          title: '申请日期',
          align: 'center',
          dataIndex: 'applicantDate',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '账面余额',
          align: 'center',
          dataIndex: 'bookBalance'
        },
        {
          title: '批准金额',
          align: 'center',
          dataIndex: 'approveAmount'
        },
        {
          title: '财务查询人',
          align: 'center',
          dataIndex: 'financeUserName'
        },
        {
          title: '查询日期',
          align: 'center',
          dataIndex: 'queryDate',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '请付金额',
          align: 'center',
          dataIndex: 'pleasePayAmount'
        },
        {
          title: '最终批准金额',
          align: 'center',
          dataIndex: 'endApproveAmount'
        },
        {
          title: '制单人',
          align: 'center',
          dataIndex: 'createBy'
        },
        {
          title: '制单部门',
          align: 'center',
          dataIndex: 'sysOrgCode'
        },
        {
          title: '制单日期',
          align: 'center',
          dataIndex: 'createTime'
        },
        {
          title: '是否变更',
          align: 'center',
          dataIndex: 'isUpdate_dictText'
        },
        {
          title: '是否开启',
          align: 'center',
          dataIndex: 'isOpen_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/procurement/fundingApplication/list',
        delete: '/procurement/fundingApplication/delete',
        deleteBatch: '/procurement/fundingApplication/deleteBatch',
        exportXlsUrl: '/procurement/fundingApplication/exportXls',
        importExcelUrl: 'procurement/fundingApplication/importExcel',
        open: '/procurement/fundingApplication/open',
        close: '/procurement/fundingApplication/close',
        update: '/procurement/fundingApplication/update'
      },
      dictOptions: {},
      superFieldList: []
    }
  },
  created() {
    // 检查 localStorage 中是否有标记
    const autoAdd = localStorage.getItem('autoAddFunding');
    if (autoAdd === 'true') {
      // 立即清除标记，防止刷新后重复触发
      localStorage.removeItem('autoAddFunding');
      // 获取传递的参数
      const params = JSON.parse(localStorage.getItem('fundingParams') || {});
      localStorage.removeItem('fundingParams');
      // 弹出表单
      this.$nextTick(() => {
        this.$refs.modalForm.add(params);
        this.$refs.modalForm.title = "新增";
        this.$refs.modalForm.disableSubmit = false;
      });
    }
    this.getSuperFieldList()
    this.startTime_begin = moment().subtract(7, 'days').format(this.dateFormat)
    this.startTime_end = moment().format(this.dateFormat)
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {


    handleDelete: function (id) {
      if (!this.url.delete) {
        this.$message.error("请设置url.delete属性!")
        return
      }
      var that = this;
      deleteAction(that.url.delete, {id: id}).then((res) => {
        if (res.success) {
          //重新计算分页问题
          that.reCalculatePage(1)
          that.$message.success(res.message);
          that.handleChangeTab();
        } else {
          that.$message.warning(res.message);
        }
      });
    },

    searchResetUnCreated() {
      this.startTime_begin = moment().subtract(7, 'days').format(this.dateFormat)
      this.startTime_end = moment().format(this.dateFormat)
      this.loadNotGeneratedData()
    },
    handleUpdate(record){
      this.$refs.modalForm.edit({
        ...record,
        isUpdate: "1"
      });
      this.$refs.modalForm.title = "变更资金申请";
      this.$refs.modalForm.disableSubmit = false;
      this.loadApprovingData()
    },
    handelOpen(record) {
      httpAction(this.url.open, record, 'put').then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.loadApprovedData()
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    handelClose(record) {
      httpAction(this.url.close, record, 'put').then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.loadApprovedData()
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    /**  取消流程申请 */
    handelSubmitCancel(row) {
      const params = {
        instanceId: row.processInstanceId
      }
      stopProcess(params).then((res) => {
        this.$message.success(res.message)
        this.loadApprovingData()
      })
    },
    handleChangeTab() {
      switch (this.activeKey) {
        case 'notGenerated':
          this.loadNotGeneratedData()
          break
        case 'needEdit':
          this.loadNeedEditData()
          break
        case 'approving':
          this.loadApprovingData()
          break
        case 'approved':
          this.loadApprovedData()
          break
        case 'toBePaid':
          this.loadToBePaidData()
          break
        case 'paid':
          this.loadPaidData()
          break
        default:
          break
      }
    },
    loadNotGeneratedData() {
      //暂存中，status=-2
      this.tabIndex = 0
      let para = {
        ...this.queryParam,
        status: -2,
        createTimeBg: this.startTime_begin + ' 00:00:00',
        createTimeEd: this.startTime_end + ' 23:59:59'
      }
      this.notGeneratedTable.loading = true
      getAction(this.url.list, para)
        .then((res) => {
          if (res.success) {
            this.notGeneratedTable.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.notGeneratedTable.loading = false
        })
    },
    //需修改
    loadNeedEditData() {
      this.tabIndex = 1
      //需修改单据，status=-1
      this.queryParam.status = -1
      this.needEditTable.loading = true
      getAction(this.url.list, this.queryParam)
        .then((res) => {
          if (res.success) {
            this.needEditTable.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.needEditTable.ipagination.total = res.result.total
            } else {
              this.needEditTable.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.needEditTable.loading = false
        })
    },
    //审判中
    loadApprovingData() {
      this.tabIndex = 2
      //审核中单据，status=0
      this.queryParam.status = 0
      this.approvingTable.loading = true
      getAction(this.url.list, this.queryParam)
        .then((res) => {
          if (res.success) {
            this.approvingTable.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.approvingTable.ipagination.total = res.result.total
            } else {
              this.approvingTable.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.approvingTable.loading = false
        })
    },
    //已审批
    loadApprovedData() {
      this.tabIndex = 3
      //已审核单据，status=999
      let para = {
        ...this.queryParam,
        status: [999,3,2,4]
      }
      this.approvedTable.loading = true
      getAction(this.url.list, para)
        .then((res) => {
          if (res.success) {
            this.approvedTable.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.approvedTable.ipagination.total = res.result.total
            } else {
              this.approvedTable.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.approvedTable.loading = false
        })
    },
    //待支付
    loadToBePaidData(){
      this.tabIndex = 4
      //待支付单据，status=999
      let para = {
        ...this.queryParam,
        status: [999,4]
      }
      this.toBePaidTableTable.loading = true
      getAction(this.url.list, para)
        .then((res) => {
          if (res.success) {
            this.toBePaidTableTable.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.toBePaidTableTable.ipagination.total = res.result.total
            } else {
              this.toBePaidTableTable.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.toBePaidTableTable.loading = false
        })
    },
    //已支付
    loadPaidData(){
      this.tabIndex = 5
      //已支付单据，status=3
      let para = {
        ...this.queryParam,
        status: 3
      }
      this.paidTableTable.loading = true
      getAction(this.url.list, para)
        .then((res) => {
          if (res.success) {
            this.paidTableTable.dataSource = (res.result.records || []).map(item => ({
              ...item,
              pleasePayAmount: item.approveAmount
            }));
            if (res.result.total) {
              this.paidTableTable.ipagination.total = res.result.total
            } else {
              this.paidTableTable.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.paidTableTable.loading = false
        })
    },
    async loadData() {
      //分别根据单据状态查询结果并将其放在
      this.queryParam = this.getQueryParams()
      console.log("this.queryParam")
      console.log(this.queryParam)
      this.loadNotGeneratedData()
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'fundingApplicationNum', text: '资金申请单号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'vendorName', text: '供应商名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'documentType', text: '单据类型', dictCode: '' })
      fieldList.push({ type: 'string', value: 'approvalProcess', text: '审批流程', dictCode: '' })
      fieldList.push({ type: 'string', value: 'procurementCode', text: '采购订单号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'procurementEnterprises', text: '采购企业', dictCode: '' })
      fieldList.push({ type: 'int', value: 'applicantAmount', text: '申请金额', dictCode: '' })
      fieldList.push({ type: 'int', value: 'currency', text: '币种', dictCode: '' })
      fieldList.push({ type: 'string', value: 'applicant', text: '申请人', dictCode: '' })
      fieldList.push({ type: 'date', value: 'applicantDate', text: '申请日期' })
      fieldList.push({ type: 'int', value: 'fundingCategory', text: '资金类别', dictCode: '' })
      fieldList.push({ type: 'int', value: 'bookBalance', text: '账面余额', dictCode: '' })
      fieldList.push({ type: 'string', value: 'financeUserName', text: '财务查询人', dictCode: '' })
      fieldList.push({ type: 'date', value: 'queryDate', text: '查询日期' })
      fieldList.push({ type: 'int', value: 'approveAmount', text: '批准金额', dictCode: '' })
      fieldList.push({ type: 'string', value: 'capitalizedAmount', text: '金额大写', dictCode: '' })
      fieldList.push({ type: 'string', value: 'applicantReason', text: '申请说明', dictCode: '' })
      fieldList.push({ type: 'string', value: 'contractTerms', text: '合同条款', dictCode: '' })
      fieldList.push({ type: 'string', value: 'suppliesObtained', text: '所获物资', dictCode: '' })
      fieldList.push({ type: 'string', value: 'isOpen', text: '是否开启', dictCode: 'yes_no' })
      fieldList.push({ type: 'string', value: 'isUpdate', text: '是否变更', dictCode: 'yes_no' })
      fieldList.push({ type: 'string', value: 'status', text: '状态', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>